set nocompatible

source $VIMRUNTIME/vimrc_example.vim

"source $VIMRUNTIME/mswin.vim

"behave mswin

 

set diffexpr=MyDiff()

function MyDiff()

  let opt = '-a --binary '

  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif

  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif

  let arg1 = v:fname_in

  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif

  let arg2 = v:fname_new

  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif

  let arg3 = v:fname_out

  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif

  let eq = ''

  if $VIMRUNTIME =~ ' '

    if &sh =~ '\<cmd'

      let cmd = '""' . $VIMRUNTIME . '\diff"'

      let eq = '"'

    else

      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'

    endif

  else

    let cmd = $VIMRUNTIME . '\diff'

  endif

  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq

endfunction

 

 

"设置文件的代码形式 utf8

set encoding=utf-8

set termencoding=utf-8

set fileencoding=utf-8

set fileencodings=ucs-bom,utf-8,chinese,cp936

 

"vim的菜单乱码解决

source $VIMRUNTIME/delmenu.vim

source $VIMRUNTIME/menu.vim

 

"vim提示信息乱码的解决

language messages zh_CN.utf-8

 

filetype on

filetype plugin indent on

"colorscheme evening "配色方案
"colorscheme desert
"colorscheme molokai
"colorscheme tatami
"set background=light
colorscheme solarized
set background=dark

set helplang=cn "设置中文帮助

set history=500 "保留历史记录

set guifont=Consolas:h13 "设置字体为Monaco，大小10

set tabstop=4 "设置tab的跳数

set sw=4  "shiftwidth设置为 4
set ts=4  "tabstop 设置为4
 
filetype indent on "开启自动的缩进检测
autocmd FileType python setlocal et sta sw=4 sts=4 "根据Python语言的建议（将tab展成四个空格）进行了专门设置

set expandtab

set backspace=2 "设置退格键可用

set number "设置显示行号
set relativenumber "设置相对行号

set wrap "设置自动换行

"set nowrap "设置不自动换行

set linebreak "整词换行，与自动换行搭配使用

"set list "显示制表符

set autochdir "自动设置当前目录为正在编辑的目录

set hidden "自动隐藏没有保存的缓冲区，切换buffer时不给出保存当前buffer的提示

set scrolloff=5 "在光标接近底端或顶端时，自动下滚或上滚

"Toggle Menu and Toolbar "隐藏菜单栏和工具栏

"set guioptions-=m

"set guioptions-=T

set showtabline=2 "设置显是显示标签栏

set autoread "设置当文件在外部被修改，自动更新该文件

set mouse=a "设置在任何模式下鼠标都可用

set nobackup "设置不生成备份文件
set nowritebackup

"set go= "不要图形按钮

set guioptions-=T           " 隐藏工具栏

"set guioptions-=m           " 隐藏菜单栏

"===========================

"查找/替换相关的设置

"===========================

set hlsearch "高亮显示查找结果

set incsearch "增量查找

"===========================

"状态栏的设置

"===========================

set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%] "显示文件名：总行数，总的字符数

set ruler "在编辑过程中，在右下角显示光标位置的状态行

"===========================

"代码设置

"===========================

syntax enable "打开语法高亮

syntax on "打开语法高亮

set showmatch "设置匹配模式，相当于括号匹配

set smartindent "智能对齐

"set shiftwidth=4 "换行时，交错使用4个空格

set autoindent "设置自动对齐

set ai! "设置自动缩进

"set cursorcolumn "启用光标列

set cursorline "启用光标行

set guicursor+=a:blinkon0 "设置光标不闪烁

set fdm=indent "

set nofoldenable "完全禁用掉vim的折叠功能

set wildmenu "tab键提示命令



"-------------------------------------------自定义命令及特殊功能 start-------------------------------------------------- 

" 设置全屏启动 start
function! MaximizeWindow()    
	silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
if has('win32')    
	au GUIEnter * simalt ~x
else    
	au GUIEnter * call MaximizeWindow()
endif 
" 设置全屏启动 end

" json格式化
command! JsonFormat :execute '%!python -m json.tool'
\ | :execute '%!python -c "import re,sys;chr=__builtins__.__dict__.get(\"unichr\", chr);sys.stdout.write(re.sub(r\"\\u[0-9a-f]{4}\", lambda x: chr(int(\"0x\" + x.group(0)[2:], 16)).encode(\"utf-8\"), sys.stdin.read()))"'
\ | :set ft=javascript
\ | :1

"-------------------------------------------自定义命令及特殊功能 end-------------------------------------------------- 


"-------------------------------------------扩展功能 start-------------------------------------------------- 

" VundleVim 插件管理

"set rtp+=$VIM\vimfiles\bundle\Vundle.vim\

"call vundle#begin()

"Plugin 'VundleVim/Vundle.vim'

"Plugin 'scrooloose/nerdtree'

"Plugin 'jistr/vim-nerdtree-tabs'

"Plugin 'Xuyuanp/nerdtree-git-plugin'

"Plugin 'kien/ctrlp.vim'

"Plugin 'eshion/vim-sync'

"Plugin 'elzr/json-vim'


"call vundle#end()


" 插件管理-vim-plug
"call plug#begin('D:\Program Files (x86)\Vim\vim82\plugged')
call plug#begin('$VIM\vim82\plugged')

Plug 'mg979/vim-visual-multi', {'branch': 'master'} "多光标插件

Plug 'scrooloose/nerdtree',{'on':'NERDTreeToggle'} "NERDTree 插件

Plug 'neoclide/coc.nvim', {'branch': 'release'} "coc.nvim 代码补全插件 

Plug 'honza/vim-snippets' "代码模板插件

Plug 'gcmt/wildfire.vim', {'branch': 'master'} "wildfire 插件 

Plug 'tpope/vim-surround', {'branch': 'master'} "tpope/vim-surround 插件 

Plug 'vim-airline/vim-airline' "vim-airline 美化插件
Plug 'vim-airline/vim-airline-themes'

call plug#end()

" 自动启动 coc扩展插件
let g:coc_global_extensions = ['coc-tsserver','coc-html','coc-css', 'coc-json',
            \ 'coc-java','coc-python','coc-flutter',
            \ 'coc-emmet','coc-snippets','coc-xml','coc-yaml','coc-yank',
            \ 'coc-markdownlint','coc-highlight']


" NERDTreeToggle 配置
"将t映射为开启快捷键
map t :NERDTreeToggle<CR> 
let NERDTreeShowLineNumbers=1 "是否展示行号
let NERDTreeAutoCenter=1 "自动保持在中间
let NERDTreeShowHidden=0 " 是否显示隐藏文件
let NERDTreeWinSize=31 " 设置宽度
let NERDTreeIgnore=['\.pyc','\~$','\.swp'] "忽略以下文件的显示
let NERDTreeShowBookmarks=1 "显示书签列表

" vim-airline
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1


" coc.vim 插件配置 --------------------------  start -------------------------------

" Set internal encoding of vim, not needed on neovim, since coc.nvim using some
" unicode characters in the file autoload/float.vim
set encoding=utf-8

" TextEdit might fail if hidden is not set.
set hidden

" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup

" Give more space for displaying messages.
set cmdheight=2

" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300

" Don't pass messages to |ins-completion-menu|.
set shortmess+=c

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("nvim-0.5.0") || has("patch-8.1.1564")
  " Recently vim can merge signcolumn and number column into one
  set signcolumn=number
else
  set signcolumn=yes
endif

" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif

" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  elseif (coc#rpc#ready())
    call CocActionAsync('doHover')
  else
    execute '!' . &keywordprg . " " . expand('<cword>')
  endif
endfunction

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code.
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
  autocmd!
  " Setup formatexpr specified filetype(s).
  autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  " Update signature help on jump placeholder.
  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac  <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf  <Plug>(coc-fix-current)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)

" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
  nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif

" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)

" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')

" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>

" coc-yark
nnoremap <silent> <space>y  :<C-u>CocList -A --normal yank<cr>

" coc.vim 插件配置 --------------------------  end ---------------------------------


"-------------------------------------------扩展功能 end-------------------------------------------------- 
